<?php
    class template extends model 
    {
          private $data;
          function setdata($data)
          {
          
           $this->data=$data;
          
          }
          function load($file)
         {

         
             if($this->checkpermission($file,1))
             {
               global $db_exec;
               
               $db_exec->get_connect();
               
               $this->setdb($db_exec);
               
               
               
               
               
               $this->data;
               //$this->get['shelfid'];

               if($this->checkadmin())
               {
                $this->data['linkmain']=baseinfo.'/portalshelf';
                $this->data['linkadd']=baseinfo.'/createshelf'; 
                $this->data['admin']=1;
                if($this->checkpermission($file,2))
                {
                
                include(rootpath.'/templates/'.template.'/'.$file.'.php');
                
                }else
                {
                
                if($this->checkpermission($file,4))
                {
                
                 include(rootpath.'/templates/'.template.'/'.$file.'.php');
                
                }else
                {
               if($this->checkpermission($file,3)&&$_GET['shelfid'])
                {
                //$this->data['linkmain']=baseinfo;
                $this->data['userpremium']=$this->getuserbyoauth($_COOKIE['oauth']);
                $this->data['userpremium']['shelfid']=$_GET['shelfid'];
                $this->data['userpremium']['admin']=1; 
                $this->data['linkadd']=baseinfo.'/addbook?shelfid='.$this->data['userpremium']['shelfid']; 
                $this->data['usershelf']=$this->getshelfbyshelfid($this->data['userpremium']['shelfid']);
                $this->data['userbanner']=$this->getbannerbyshelfid($this->data['userpremium']['shelfid']); 
                $this->data['userbannerlibrary']=$this->getbannerlibrarybyshelfid($this->data['userpremium']['shelfid']);
                $this->data['usermytag']=$this->getmytagbyuserid($this->data['userpremium']['userid']);
                $this->data['useralltag']=$this->getalltagbyshelfid($this->data['userpremium']['shelfid']);  
                $this->data['fileset']=$file;
                include(rootpath.'/templates/'.template.'/'.$file.'.php'); 
                
                }
                else
                { 
                include(rootpath.'/templates/'.template.'/error.php');  
                }
                }
                
                
                
                
                
                } 
                 
               
               }else
               {
               $this->data['linkmain']=baseinfo;
                

                
               if($this->checkpermission($file,3))
                {
                $this->data['userpremium']=$this->getuserbyoauth($_COOKIE['oauth']);
                $this->data['linkadd']=baseinfo.'/addbook?shelfid='.$this->data['userpremium']['shelfid']; 
                $this->data['usershelf']=$this->getshelfbyshelfid($this->data['userpremium']['shelfid']);
                $this->data['userbanner']=$this->getbannerbyshelfid($this->data['userpremium']['shelfid']); 
                $this->data['userbannerlibrary']=$this->getbannerlibrarybyshelfid($this->data['userpremium']['shelfid']);
                $this->data['usermytag']=$this->getmytagbyuserid($this->data['userpremium']['userid']);
                $this->data['useralltag']=$this->getalltagbyshelfid($this->data['userpremium']['shelfid']);  
                $this->data['fileset']=$file;
                include(rootpath.'/templates/'.template.'/'.$file.'.php'); 
                }else
                {

                 if($this->checkpermission($file,4))
                {
                 include(rootpath.'/templates/'.template.'/'.$file.'.php');
                
                }else
                {
                include(rootpath.'/templates/'.template.'/login.php');  
                
                }
                
                }
               
               }
               
               
                  
               
               $db_exec->closedb(); 
             
             }
             else
             {
             $arrayfileuser=array("forgotpassword","login","resetpassword","checkmail"); 
                if(in_array($file,$arrayfileuser))
              {
              include(rootpath.'/templates/'.template.'/'.$file.'.php');
              }else
              {
              
              include(rootpath.'/templates/'.template.'/login.php');
              }
                
             
             }
             
         }
         
          function loadfile($settemplate,$file)
          {
          include(rootpath.'/templates/'.$settemplate.'/'.$file);
          
          }
    
    }
?>
